<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    {include file='base/common_header'}
    <style>
        .layui-table td, .layui-table th { min-width: auto; }
    </style>
</head>

<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="/admin">首页</a>
                <a href="/admin/topic">测评列表</a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">
                        <div class="layui-input-inline layui-show-xs-block">
                            <select name="category">
                                <option value="0" {if $category eq 0}selected{/if}>全部</option>
                                {volist name='categoryList' id='c' key='k'}
                                <option value="{$c.id}" {if $category eq $c.id}selected{/if}>{$c.name}</option>
                                {/volist}
                            </select>
                        </div>
                        <div class="layui-input-inline layui-show-xs-block">
                            <input type="text" value="{$title}" name="title" placeholder="请输入标题" autocomplete="off" class="layui-input"></div>
                        <div class="layui-input-inline layui-show-xs-block">
                            <button class="layui-btn" lay-submit="" lay-filter="sreach">
                                <i class="layui-icon">&#xe615;</i></button>
                            <button type="button" class="layui-btn" onclick="xadmin.open('添加题目','/admin/topic/add','','',true)">
                                <i class="layui-icon"></i>添加</button>
                            <button type="button" class="layui-btn layui-btn-normal" onclick="updateMedia()">
                                更新公众号图文素材</button>
                            &nbsp;<span style="color: red;">{if $setStatus}已经更新了图文素材{else}请更新图文素材{/if}</span>
                        </div>
                    </form>
                </div>
                <div class="layui-card-body ">
                    <table class="layui-table layui-form">
                        <thead>
                        <tr>
                            <th>ID</th>
                            <th>标题</th>
                            <th>图片</th>
                            <th>热门爆款</th>
                            <th>上新测试</th>
                            <th>总测试数据</th>
                            <th>昨日数据</th>
                            <th>今日数据</th>
                            <th>是否发布</th>
                            <th width="25%">操作</th></tr>
                        </thead>
                        <tbody>
                        {volist name='list' id='topic'}
                        <tr>
                            <td>{$topic.topic_id}</td>
                            <td>{$topic.title}</td>
                            <td><img src="{$topic.banner_img}" width="80px" height="60px"/> </td>
                            <td><input type="checkbox" name="top" value="{$topic.topic_id}" lay-skin="switch" lay-filter="top" {if $topic.is_recommend eq 1}checked{/if}></td>
                            <td><input type="checkbox" name="icon_type" value="{$topic.topic_id}" lay-skin="switch" lay-filter="icon_type" {if $topic.icon_type eq 1}checked{/if}></td>
                            <td>
                                人数：{$topic.totalUserCount}<br/>
                                次数：{$topic.totalCount}
                            </td>
                            <td>
                                人数：{$topic.totalYesterdayUserCount}<br/>
                                次数：{$topic.topicYesterdayCount}
                            </td>
                            </td>
                            <td>
                                人数：{$topic.totalTodayUserCount}<br/>
                                次数：{$topic.topicTodayCount}
                            </td>
                            <td><input type="checkbox" name="icon_type" value="{$topic.topic_id}" lay-skin="switch" lay-filter="is_publish" {if $topic.is_publish eq 1}checked{/if}></td>
                            <td class="td-manage">
                                <a class="layui-btn layui-btn-xs" title="编辑" onclick="xadmin.open('编辑','/admin/topic/edit/{$topic.topic_id}','','',true)" href="javascript:;">
                                    编辑</a>
                                <a class="layui-btn layui-btn-xs layui-btn-primary" title="编辑" onclick="xadmin.open('设置问题','/admin/topic/question/{$topic.topic_id}','','',true)" href="javascript:;">
                                    设置问题</a>
                                <a class="layui-btn layui-btn-xs" title="编辑" onclick="xadmin.open('设置答案','/admin/topic/answer/{$topic.topic_id}','','',true)" href="javascript:;">
                                    设置答案</a>
                                <br>
                                <a title="删除" class="layui-btn layui-btn-xs layui-btn-danger" onclick="topic_del(this,'{$topic.topic_id}')" href="javascript:;">
                                    删除</a>
                            </td>
                        </tr>
                        {/volist}
                        </tbody>
                    </table>
                </div>
                <div class="layui-card-body ">
                    {$page|raw}
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
function topic_del(obj, id) {
    layer.confirm('确认要删除吗？',
        function(index) {
            //发异步删除数据
            $.post('/admin/topic/del',{id:id},function (data) {
                console.log(data)
                if(data.error_code == 0){
                    layer.msg('操作成功!', {
                        icon: 1,
                        time: 1000
                    },function () {
                        window.location.reload()
                    });
                }else{
                    layer.msg('操作失败!', {
                        icon: 2,
                        time: 1000
                    });
                }
            },"json")

        });
}






layui.use('table', function() {
    var table = layui.table
        , form = layui.form;

    //监听banner操作
    form.on('switch(banner)', function(obj){
        var _val = obj.elem.checked == true ? 1:0
        $.post('/admin/topic/deal',{id:this.value,type:'banner',status:_val},{},function (data) {
            if(data.error_code == 0){
                layer.tips('修改成功', obj.othis);
            }else{
                layer.tips('修改失败',obj.othis);
            }
        },"json")
    });
    //监听精选操作
    form.on('switch(top)', function(obj){
        var _val = obj.elem.checked == true ? 1:0
        $.post('/admin/topic/deal',{id:this.value,type:'top',status:_val},{},function (data) {
            if(data.error_code == 0){
                layer.tips('修改成功', obj.othis);
            }else{
                layer.tips('修改失败',obj.othis);
            }
        },"json")
    });
    //监听原创操作
    form.on('switch(icon_type)', function(obj){
        var _val = obj.elem.checked == true ? 1:0
        $.post('/admin/topic/deal',{id:this.value,type:'icon_type',status:_val},{},function (data) {
            if(data.error_code == 0){
                layer.tips('修改成功', obj.othis);
            }else{
                layer.tips('修改失败',obj.othis);
            }
        },"json")
    });
    //监听发布操作
    form.on('switch(is_publish)', function(obj){
        var _val = obj.elem.checked == true ? 1:0
        $.post('/admin/topic/deal',{id:this.value,type:'is_publish',status:_val},{},function (data) {
            if(data.error_code == 0){
                layer.tips('修改成功', obj.othis);
            }else{
                layer.tips('修改失败',obj.othis);
            }
        },"json")
    });
})

</script>

</html>